﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;
using System.Data.SqlClient;
using System.Data;
namespace EmoneyWeiXinDAL
{
    public class MenuDal
    {
        public static List<MenuEntity> getMenuList(int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid",weixinid)
            };
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menu_Select", parameters);
            return result;
        }

        public static List<MenuEntity> getMenuList(int weixinid, int userid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid",weixinid),
            new SqlParameter("@userid",userid)
            };
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menu_SelectByUserID", parameters);
            return result;
        }
        public static DataSet getMenuList2(int weixinid, int userid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid",weixinid),
            new SqlParameter("@userid",userid)
            };
            DataSet result = SQLHelper.ExecuteGetDataSet(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_menu_SelectByUserID2", parameters);
            return result;
        }
        public static List<MenuEntity> getMenuListByID(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id", id)
            };
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menu_SelectByID", parameters);
            return result;
        }
        public static DataSet getMenu_NewsReport_ListByID(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id",id)
            };
            DataSet result = SQLHelper.ExecuteGetDataSet(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_Menu_NewsReport_List", parameters);
            return result;
        }
        public static List<MenuEntity> getMenuParentList(int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid",weixinid)
            };
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menuParent_select", parameters);
            return result;
        }
        public static List<MenuEntity> getMenuChildrenList(int id, int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id",id),
            new SqlParameter("@weixinid",weixinid)
            };
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menuChildren_selectByParentID", parameters);
            return result;
        }
        public static List<MenuEntity> getMenuList()
        {
            List<MenuEntity> result = SQLHelper.GetProcedureDataByColumnsLst<MenuEntity>(Config.EmoneyWeiXin, "sp_menu_Select2", null);
            return result;
        }
        public static List<OperateEntity> getOperateList()
        {
            List<OperateEntity> result = SQLHelper.GetProcedureDataByColumnsLst<OperateEntity>(Config.EmoneyWeiXin, "sp_operate_Select", null);
            return result;
        }

        public static List<User_OperateEntity> getOperateList(int userid, int leftmemu_id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@userid",userid),
            new SqlParameter("@leftmemu_id",leftmemu_id)
            };
            List<User_OperateEntity> result = SQLHelper.GetProcedureDataByColumnsLst<User_OperateEntity>(Config.EmoneyWeiXin, "sp_operate_selectByUserID", parameters);
            return result;
        }
        public static DataSet getMenuParentAndChildren(int weixinid)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid",weixinid)
            };
            DataSet result = SQLHelper.ExecuteGetDataSet(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_menu_selectAll", parameters);
            return result;
        }

        public static int UpdateMenu(MenuEntity obj, string newsreportids)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id" , obj.id),
            new SqlParameter("@weixinuserid" , obj.weixinuserid),
            new SqlParameter("@title", obj.title),
            new SqlParameter("@everyKey", obj.everyKey),
            new SqlParameter("@keyword", obj.Keyword),
            new SqlParameter("@sort", obj.sort),
            new SqlParameter("@KeyUrl", obj.KeyUrl),
            new SqlParameter("@hisId" , obj.hisId),
            new SqlParameter("@DayType" , obj.DayType),
            new SqlParameter("@thday", obj.thday),
            new SqlParameter("@starttime", obj.starttime),
            new SqlParameter("@endtime", obj.endtime),
            new SqlParameter("@jgtimeStr", obj.jgtimeStr),
            new SqlParameter("@createtime", obj.createtime),
            new SqlParameter("@updatetime", obj.updatetime),
            new SqlParameter("@isThread" , obj.isThread),
            new SqlParameter("@contentym", obj.contentym),
            new SqlParameter("@contentyj", obj.contentyj),
            new SqlParameter("@isvalid" , obj.isvalid),
            new SqlParameter("@remark", obj.remark==null?"":obj.remark),
            new SqlParameter("@PubStatus" , obj.PubStatus),
            new SqlParameter("@orderLM", obj.orderLM==null?"":obj.orderLM),
            new SqlParameter("@unsubscribeLM", obj.unsubscribeLM==null?"":obj.unsubscribeLM),
            new SqlParameter("@VIP" , obj.VIP),
            new SqlParameter("@mtype" , obj.mtype),//菜单类型
            new SqlParameter("@linkUrl", obj.linkUrl==null?"":obj.linkUrl),	
            new SqlParameter("@isAction" , obj.isAction),//设置动作
            new SqlParameter("@isSend" , obj.isSend),////1发送信息;0跳转到网页 
            new SqlParameter("@sendMsg" , obj.sendMsg==null?"":obj.sendMsg),//发送消息内容
            new SqlParameter("@newsreportids" , newsreportids),
            new SqlParameter("@isweixinMemu" , obj.isweixinMemu),
            new SqlParameter("@isJianQuan",obj.isJianQuan)
            };
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_menu_Update", parameters);
            return result;
        }
        public static int DeleteMenu(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {  
            new SqlParameter("@id", id)};
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_menu_Delete", parameters);
            return result;
        }

        public static DataSet getMenuType()
        {
            DataSet result = SQLHelper.ExecuteGetDataSet(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_menuType_select", null);
            return result;
        }
    }
}
